package com.karolak.stock.oscilator;

import com.karolak.stock.data.DataManager;
import com.karolak.stock.indicator.Indicator;

/**
 * 
 * <code>DiffOsc</code> is used to ....
 * 
 * @author <a href="mailto:kwozniak@hotmail.com">Karol Wozniak</a>
 */
public class DiffOsc extends Oscilator {

	private Indicator input1;

	public DiffOsc(String name, DataManager dataManager, int period, Indicator input0, Indicator input1) {
		super(dataManager, period, input0);
		this.input1 = input1;
		setName(name);
	}
	
	public DiffOsc(DataManager dataManager, int period, Indicator input0, Indicator input1) {
		super(dataManager, period, input0);
		this.input1 = input1;
		setName(String.format("%s-%s-%s", super.getName(), getInput().getName(), getInput1().getName()));
	}

	public DiffOsc(String name, DataManager dataManager, Indicator input0, Indicator input1) {
		super(dataManager, 0, input0);
		this.input1 = input1;
		setName(name);
	}
	
	@Override
	public double execute(double x) {
		double v0 = getDataManager().getLast(getInput().getName());
		double v1 = getDataManager().getLast(getInput1().getName());
		double diff = v0 - v1;
		return diff;
	}

	public Indicator getInput1() {
		return input1;
	}
}
